package org.ajax.servlet;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.io.PrintWriter;

/**
 * 用户登录
 *
 * @author ZQX
 * @date 2024-11-18
 */
@WebServlet("/login.do")
public class LoginServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 第一：获取客户端传递过来的数据 - 数据合法性验证
        String username = req.getParameter("username");
        String password = req.getParameter("password");

        // 第二：业务逻辑处理 - 登录处理 - DAO
        String msg = "error" ;

        if(!"".equals(username) && !"".equals(password)) {
            msg = "success" ;
        }

        // 第三：响应数据
        PrintWriter out = resp.getWriter();
        out.write(msg);

        out.flush();
        out.close();
    }
}
